<?php

namespace App\Containers\AppSection\Pledge\UI\API\Transformers;

use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Containers\AppSection\Pledge\Models\Other;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class OtherTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'documents', 'object_documents', 'images'
    ];

    /**
     * @param Other $t
     * @return array
     */
    public function transform(Other $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'name' => $t->name,
            'characteristics' => $t->characteristics,
            'address' => $t->address,
            'other_information' => $t->other_information,
            'serial_number' => $t->serial_number,
            'date' => $t->date,
        ];
    }

    public function includeDocuments(Other $t): Collection
    {
        return $this->collection($t->documents()->get(), new FileTransformer);
    }

    public function includeImages(Other $t): Collection
    {
        return $this->collection($t->images()->get(), new FileTransformer);
    }

    public function includeObjectDocuments(Other $t): Collection
    {
        return $this->collection($t->object_documents()->get(), new FileTransformer);
    }
}
